import array
import modulefinder
import random

import matplotlib.pyplot as plt
import numpy as np

y_1 = [1, 3, 4, 6, 7, 8, 12, 13, 16, 21, 23, 25, 31, 35, 36, 37, 38, 45, 43, 32, 36, 13, 24, 25, 26, 27, 28, 12, 15, 6,
       7, 20, 14, 16, 40, 38, 35, 31, 20, 24, 25]
y_2 = []

# for i in range(1, 31):
#     y_1.append(random.randint(1, 50))

# for i in range(1, 31):
#     y_2.append(random.randint(1, 50))

x1 = range(1, len(y_1) + 1)
# x2 = range(len(y_1) + 21, len(y_1) + len(y_2) + 21)

plt.scatter(x1, y_1, label="March")
# plt.scatter(x2, y_2, label="October")

# 三次拟合
# parameter = np.polyfit(x1, y_1, 3)
# yp1 = parameter[0] * x1 * x1 * x1 + parameter[1] * x1 * x1 + parameter[2] * x1 + parameter[3]
# plt.plot(x1, yp1, color='r', label="3 polynomial fit")

# 一次拟合
parameter = np.polyfit(x1, y_1, 1)
yp2 = parameter[0] * x1
plt.plot(x1, yp2, color='g', label="1 Polynomial fit")

# 四次 拟合
# parameter = np.polyfit(x1, y_1, 4)
# yp3 = parameter[0] * x1 * x1 * x1 * x1 + parameter[1] * x1 * x1 * x1 + parameter[2] * x1 * x1 + parameter[3] * x1 + \
#       parameter[4]
# plt.plot(x1, yp3, color='b', label="4 polynomial fit")

# 六次拟合
mymodel = np.poly1d(np.polyfit(x1, y_1, 6))
myline = np.linspace(1, 40, 100)
plt.plot(myline, mymodel(myline), color="#aa823f", label="6 polynomial fit")

# pyCollect = [yp1, yp2, yp3]

mymodel = np.poly1d(np.polyfit(x1, y_1, 1))
myline = np.linspace(1, 40, 100)
plt.plot(myline, mymodel(myline), color="#00ff00", label="1 polynomial fit")


plt.legend()

plt.show()
